package org.tong.jpa.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tong.jpa.entities.Student;
import org.tong.jpa.service.inter.StudentService;

/**
 * @author
 * @date 2022-08-01 18:17
 */
@RestController
@RequestMapping("/cache/")
public class CacheController {

    @Autowired
    private StudentService studentService;

    @GetMapping("save/{id}/{name}")
    public Long saveStudent(@PathVariable Long id, @PathVariable String name) {
        Student student = new Student();
        student.setId(id);
        student.setName(name);
        return studentService.save(student);
    }

    @GetMapping("find/{id}")
    public Student findById(@PathVariable Long id) {
        return studentService.findById(id);
    }

    @GetMapping("delete/{id}")
    public Boolean deleteById(@PathVariable Long id) {
        studentService.deleteById(id);
        return true;
    }
}
